package cn.boy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import cn.boy.home.R;

public class GridViewAdapter extends BaseAdapter {
	
	String[] names;
	int[] images;
	
	Context context;
	
	public GridViewAdapter(Context context) {
		this.context = context;
	}
	
	

	public String[] getNames() {
		return names;
	}

	public void setNames(String[] names) {
		this.names = names;
	}

	public int[] getImages() {
		return images;
	}

	public void setImages(int[] images) {
		this.images = images;
	}



	public int getCount() {
		return names.length;
	}

	public Object getItem(int position) {
		return null;
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View row=convertView;

		ViewHolder holder;

		if (row==null) {
			
			row = LayoutInflater.from(context).inflate(R.layout.gridview_item, null);

			holder = new ViewHolder();
			
			holder.headImage = (ImageView)row.findViewById(R.id.iv_item);
			holder.txtTip = (TextView)row.findViewById(R.id.tv_item);
			
			row.setTag(holder);
		}
		else{
			holder = (ViewHolder) row.getTag();
		}
		
		holder.headImage.setImageResource(images[position]);
		holder.txtTip.setText(names[position]);
		return row;
	}
	
	static class ViewHolder{
		ImageView headImage;
		TextView txtTip;
	}
	
	

}
